﻿
CREATE PROCEDURE sp_User_Insert 
	-- Add the parameters for the stored procedure here
	(
				@UserLoginID varchar(50),
				@UserPassword varchar(50),
				@UserFirstName varchar(50),
				@UserLastName varchar(50),
				@UserPrimaryEmailID varchar(150),
				@UserVerificationCode varchar(50),
				@UserIsVarified bit = false,
				
				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = -1,
				@Sys_InitialPrimaryKeys varchar(100)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT,
				@UserKey int OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();
	
    INSERT INTO [User]
           (	
				[UserLoginID],
				[UserPassword],
				[UserFirstName],
				[UserLastName],
				[UserPrimaryEmailID],
				[UserVerificationCode],
				[UserIsVarified],
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
			)
     VALUES
           (
				@UserLoginID,
				@UserPassword,
				@UserFirstName,
				@UserLastName,
				@UserPrimaryEmailID,
				@UserVerificationCode,
				@UserIsVarified,
				@CurrentDataTime,
				@CurrentDataTime,
				@Sys_CreatedByID,
				@Sys_ModifiedByID,
				@Sys_DeleteType,
				0,
				@Sys_OrganizationID,
				@Sys_InitialPrimaryKeys,
				@Sys_WorkstationName
			);
	SET @UserKey = SCOPE_IDENTITY();
	SET @Sys_DateOfCreation = @CurrentDataTime;
END
